<?php

Raise::load('core.RaiseFile');

/**
 * RaiseMailAttachment class
 * defines a file that will be attached to a RaiseMail object as an email attachment
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.Core.Mail
 * @since 1.2
 */
class RaiseMailAttachment extends RaiseFile {
    /**
     * The MIME Type of this MailAttachment
     * @var string
     */
    private $mimeType;

    /**
     * The default encoding used for attachments
     */
    const DEFAULT_ENCODING = 'base64';

    /**
     * Creates a new email attachment that can be attached to a RaiseMail
     * @param string $f The file on the local storage to attach
     * @param string $m The MIME type of the file
     */
    public function __construct($f, $m){
        parent::__construct($f);
        $this->mimeType($m);
    }

    /**
     * Get or set the MIME type of this email attachment
     * @param string $m (optional) Set the new value
     * @return string
     */
    public function mimeType($m = null){
        if(func_num_args() == 1){
            $this->mimeType = $m;
        }
        return $this->mimeType;
    }

    /**
     * Gets the content of the file and prepare it for use in email
     * @return string
     */
    public function data(){
        return chunk_split(base64_encode($this->getContent()));
    }
}
